package org.xxpay.pay.channel.payeasepay.demo;

import com.sun.jersey.api.client.Client;
import com.sun.jersey.api.client.WebResource;
import com.sun.jersey.core.util.MultivaluedMapImpl;
import org.xxpay.pay.channel.payeasepay.demo.CFCA.MerchantX509Cert;
import org.xxpay.pay.channel.payeasepay.util.XmlUtils;

import javax.ws.rs.core.MultivaluedMap;
import java.util.Map;

public class Payment_status {
    private static final String SINGLE_CHECK_URL = "https://pay.yizhifubj.com/merchant/order/order_ack_oid_list.jsp";

    public static void main(String[] args) throws Exception {
        Map<String, String> map = submit(); //

        System.out.println("-----------------------------------------------------");
        System.out.println(map); // 获得接口返回xml数据

    }

    public static Map<String, String> submit() throws Exception {
        System.setProperty("https.protocols", "TLSv1.2,TLSv1.1,SSLv3");
        Client cc = Client.create();
        WebResource rr = cc.resource(SINGLE_CHECK_URL);

        MultivaluedMap queryParams = new MultivaluedMapImpl();

        String v_mid = "19482";
        String v_oid = "20181217-19482-P01201812170339045580008";

        /*//MD5加密
        com.capinfo.crypt.Md5 md5 = new com.capinfo.crypt.Md5("");
        //v_moneytype v_ymd v_amount v_oid v_mid v_branch v_url
        md5.hmac_Md5(v_moneytype + v_ymd + v_amount + v_rcvname + v_oid + v_mid + v_url, "test");//第一个参数是加密参数，第二个参数是加密密钥，测试密钥：test，正式上线之前注意修改
        byte b[]= md5.getDigest();
        String v_md5info = md5.stringify(b);//订单数字指纹
        System.out.println("MD5签名：" + v_md5info);*/

        String pfxFile = "D:/certificate/payease/19482_private.pfx";//商户私钥文件
        String pfxPassword = "payN6886";//私钥键入密码
        String aliasPassword = "payN6886";//
        String aliasName = "{ae87b4b1-262d-4005-8cdc-9b7530f7cc21}";//别名
        String src = v_mid + v_oid;
        System.out.println("加密前的拼串：" + src);
        String sign = MerchantX509Cert.sign(src, pfxFile, aliasName, pfxPassword, aliasPassword);
        System.out.println("CFCA签名：" + sign);

        queryParams.add("v_mid", v_mid);
        queryParams.add("v_oid", v_oid);
        queryParams.add("v_mac", sign);
        String ret = rr.queryParams(queryParams).post(String.class);
        Map<String,String> resultMap = XmlUtils.xml2Map(ret);
        return resultMap;
    }
}
